<template>
    <view>
        <view>
				<view>路灯ID：{{code}}</view>
                <view>路灯名称:{{name}}</view>
				 <view>经度{{position.convers[0].longitude}}</view>
				 <view>维度{{position.convers[0].latitude}}</view>
				
				<map :latitude="position.latitude" :longitude="position.longitude" scale="16" id="myMap" style="width:100%;height:900rpx;" :markers="position.convers" @regionchange="getCenterLocation">
				</map> 
				 <button v-on:click="saveLocation()">更新坐标</button>
        </view>
    </view>
</template>p
<script>
    export default {
        data() {
            return {
				mapCtx:'',
				code:'',
				name:'',
				position:{
					longitude:113.07845,
					latitude:22.59514,
					convers:[
						{
							latitude:22.618813565184746,
							longitude:113.05628099361725
						}
					]
				}
            }
        },
        methods: {
			getCenterLocation() {
				let that = this;
			   //获取当前地图中心的经纬度 
			   this.mapCtx.getCenterLocation({
			     success(res) {
					that.position.convers = [];
					that.position.convers.push({
						longitude:res.longitude,
						latitude:res.latitude
					})
			     }
			   })
			},
			saveLocation(){
				for(let lamp of this.$lamps.data.list){
					if(lamp.code ===this.code){
						lamp.longitude = this.position.convers[0].longitude
						lamp.latitude = this.position.convers[0].latitude
					}
				}
			}
        },
		onLoad:function(option){
			this.code = option.code;
			this.name = option.name;
			for(let lamp of this.$lamps.data.list){
				if(lamp.code ===this.code){
					this.position.convers[0].longitude = lamp.longitude 
					this.position.convers[0].latitude = lamp.latitude
					this.position.longitude = lamp.longitude 
					this.position.latitude = lamp.latitude
				}
			}
		},
		onReady() {
			this.mapCtx = uni.createMapContext('myMap')
		}
    }
</script>

<style>
    .uni-form-item .title {
        padding: 20rpx 0;
    }
	.c_map{
		width: 100%;
		height: 500rpx;
	}
</style>